import java.awt.*;
import java.awt.image.BufferedImage;
import java.io.*;
import java.util.*;

import javax.imageio.ImageIO;
import javax.swing.*;

public class Main 
{
	protected static Scanner s = new Scanner(System.in);
	public static void main(String[] args)
	{
		Menu mainMenu = new Menu();
		int action = -1;
		while (true)
		{
			action = mainMenu.go();
			if (action == 0)
			{
				System.exit(0);
			}
			else if (action == 1)
			{
				WorldGen wg = new WorldGen();
			}
			else
			{
				World w = WorldGen.makeWorld(1);
				
				Terraria t = new Terraria(w, new Player(w.defXSpawn,w.defYSpawn));
				t.start();
			}
		}
	    //		World w = WorldGen.makeWorld(0);
	    //	    	System.out.println("World Gen'd");
		/*try {
			worldMap(w);
		} catch (IOException e) {
		}*/
	    //		w.save();
//	    Menu m = new Menu();
	//    if (m.go()==0) {System.exit(0);}
	}
	//for testing
	static public void worldMap(World w) throws IOException
	{	
		BufferedImage img = new BufferedImage(w.width,w.height,BufferedImage.TYPE_INT_ARGB);
		Color brown = new Color(166,42,42);
		for(int i = 0;i<w.width;i++)
		{
			for(int j=0; j<w.height;j++)
			{
				if(w.foreground[i][j].type==Blocks.DIRT)
				{
					img.setRGB(i,w.height-1-j,brown.getRGB());
				}
				else if(w.foreground[i][j].type==Blocks.SAND)
				{
					img.setRGB(i,w.height-1-j,Color.yellow.getRGB());
				}
				else if(w.foreground[i][j].water>.5)
				{
					img.setRGB(i,w.height-1-j,Color.blue.getRGB());
				}
				else
				{
					img.setRGB(i,w.height-1-j,Color.WHITE.getRGB());
				}
			}
		}

//		Graphics2D g = img.createGraphics();
		ImageIcon icon = new ImageIcon();
		icon.setImage(img);
		JOptionPane.showMessageDialog(null, icon);
		File output = new File("Mapping.png");
		ImageIO.write(img, "png", output);
	}




}
